import gradio as gr
import requests

def optimize_prompt(text):
    response = requests.post("http://127.0.0.1:8000/optimize/", json={"text": text})
    if response.status_code == 200:
        return response.json()["optimized_text"]
    else:
        return "Error: Could not connect to the backend."

iface = gr.Interface(
    fn=optimize_prompt,
    inputs=gr.Textbox(lines=7, placeholder="Enter your prompt here..."),
    outputs="text",
    title="Prompt Optimizer",
    description="Enter a prompt and get an optimized version.",
)

if __name__ == "__main__":
    iface.launch()
